package com.tiancheng.onecode.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 清分周期类型枚举
 *
 * @author konkera
 * @date 2021/7/16
 */
@Getter
@AllArgsConstructor
public enum MerchantSettleRuleCycleTypeEnum {
    DAY("T", "按日"),
    MONTH("M", "按月固定日"),
    ;

    private final String value;
    private final String name;

    /**
     * 根据值获取描述
     *
     * @param value {@link String}
     * @return {@link String}
     */
    public String getNameByValue(String value) {
        return Arrays.stream(values()).filter(d -> Objects.equals(value, d.getValue())).findFirst()
                .map(MerchantSettleRuleCycleTypeEnum::getName).orElse("");
    }

    /**
     * 根据值获取枚举
     *
     * @param value {@link String}
     * @return {@link MerchantSettleRuleCycleTypeEnum}
     */
    public static MerchantSettleRuleCycleTypeEnum getByValue(String value) {
        return Arrays.stream(values()).filter(d -> Objects.equals(value, d.getValue())).findFirst().orElse(null);
    }
}
